<template>
  <div>
    <!-- 查询  -->
      <el-popover placement="bottom-start" width="820"  trigger="click">
      <el-form :inline="true" label-width="90px" :model="search"  class="search-panle">
        <el-form-item label="部门名称" ><el-input v-model="search.userName" ></el-input></el-form-item>
        <el-form-item label="发生时间" ><el-date-picker v-model="search.reqTime"  type="daterange"   range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" align="right"></el-date-picker></el-form-item>
        <el-button type="primary" @click="searchClick">提交</el-button>
      </el-form>
      <el-button slot="reference" type="primary">查询</el-button>
    </el-popover>
    &nbsp;
    <el-button type="primary"  @click="addDept">新增部门</el-button>
    <!-- 表格-->
    <el-table :data="tableData" stripe border class="user-table" :height="tableHeight" style="width: 100%;">
      <el-table-column fixed type="index" label="*" sortable min-width="30"></el-table-column>
      <el-table-column prop="dept_name" label="部门名称" sortable min-width="180"></el-table-column>
      <el-table-column prop="dept_code" label="部门编码" sortable min-width="180"></el-table-column>
      <el-table-column prop="dept_desc" label="部门描述" sortable min-width="300"></el-table-column>
      <el-table-column fixed="right" label="操作" align="right" min-width="70">
        <template slot-scope="scope">
          <el-button @click="updatedepts(scope.row)" type="text" size="small">编辑</el-button>
          <el-button @click="updatedepts(scope.row)" type="text" size="small">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage" :page-sizes="[10, 15,20, 25,30,50, 100]" :page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"></el-pagination>
 
    <!-- 新增部门 -->
    <el-dialog class="addRoleDialog" title="新增部门" :visible.sync="dialog.isShow">
        <el-form ref="ruleForm" :model="form" status-icon  class="demo-ruleForm">
          <el-form-item label="名称：" prop="name" :label-width="formLabelWidth">
            <el-input v-model="form.name" type="text" placeholder="请输入名称" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="编码：" prop="code" :label-width="formLabelWidth">
            <el-input v-model="form.code" type="text" placeholder="请输入编码" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="描述：" prop="describe" :label-width="formLabelWidth">
          <el-input
                  type="textarea"
                  :autosize="{ minRows: 2, maxRows: 4}"
                  placeholder="请输入内容"
                  v-model="form.describe">
          </el-input>
          </el-form-item>
          <el-button @click="[dialog.isShow = false]" style="float:right;margin:0px 15px 10px 5px">取 消</el-button>
          <el-button type="primary" style="float:right;margin:0px 15px 10px 5px">确定</el-button>
          <br/>
        </el-form>  
    </el-dialog>  
  </div>
</template>
<script>
// import api from 'plugins/axios/api.js';
import {mapState} from 'vuex'
export default {
  data(){
    return {
      deptData:[],/**部门列表 */
      tableData:[
        {dept_name:'医务部',dept_code:'JY_06',dept_desc:'医务部'},
        {dept_name:'医学部',dept_code:'JY_05',dept_desc:'医学部'},
        {dept_name:'流程部',dept_code:'JY_04',dept_desc:'流程部'},
        {dept_name:'护理部',dept_code:'JY_03',dept_desc:'护理部'},
        {dept_name:'市场部',dept_code:'JY_02',dept_desc:'市场部'},
        {dept_name:'行政部',dept_code:'JY_07',dept_desc:'行政部'},
        {dept_name:'财务部',dept_code:'JY_01',dept_desc:'财务部'},
      ],
      pagination:{/**分页参数 */
        currentPage:1,
        pageSize:10,
        total:0
      },
      search:{
        userName:'测试1',
        reqTime:'测试2'
      },
      dialog:{/**弹框配置 */
        title:'',
        isShow:false
      },
      form:{},
      formLabelWidth:120+'px'
    }
  },
  watch:{
  },
  computed:{
    ...mapState({clientHeight:state=>state.common.clientHeight}),
    tableHeight(){
      return this.clientHeight-184;
    }
  },
  created(){

  },
  methods:{
    searchClick(){

    },
    addDept(){
      let self = this;
      self.dialog.isShow = true;
      self.dialog.title = "";
    },
    updatedepts(){},
    getDeptData(){/**获取角色列表 */
      let self = this;
      // api.getAlldepts().then(res=>{
      //   self.deptData= res.content;
      //   self.pagination.total =res.content.length;
      //   this.getTableData();
      // })
    },    
    handleSizeChange(size){/**切换分页条数 */
      this.pagination.pageSize=size;
      this.pagination.currentPage=1;
      this.getTableData();
    },
    handleCurrentChange(current){/**切换分页页数 */
      this.pagination.currentPage=current;
      this.getTableData();
    },    
    getTableData(){/**获取表格列表 */
      this.tableData = this.deptData.slice((this.pagination.currentPage-1)*this.pagination.pageSize,this.pagination.currentPage*this.pagination.pageSize);
    },
  }
}
</script>
<style lang="stylus" scoped>

</style>
